package com.hb.trade.server.project.section.controller;


import com.hb.core.pojo.parent.PageResult;
import com.hb.core.pojo.project.section.dto.TradeSecondQuotationBidInfoDto;
import com.hb.trade.server.project.section.service.raw.TradeSecondQuotationBidInfoService;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.model.msg.Message;
import org.fzzn.core.util.MsgUtil;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 二次报价标段信息表 前端控制器
 * </p>
 *
 * @author fengbin
 * @since 2022-02-21
 */
@Slf4j
@RestController
public class TradeSecondQuotationBidInfoController {

    protected final TradeSecondQuotationBidInfoService tradeSecondQuotationBidInfoService;

    public TradeSecondQuotationBidInfoController(TradeSecondQuotationBidInfoService tradeSecondQuotationBidInfoService) {
        this.tradeSecondQuotationBidInfoService = tradeSecondQuotationBidInfoService;
    }

    /**
     * Description: 根据标段id初始化报价信息
     *
     * @param tradeSecondQuotationBidInfoDto
     * @author: fengbin
     * @date: 2022/2/21 11:30
     * @return: java.util.List<com.hb.core.pojo.project.section.dto.TradeSecondQuotationBidInfoDto>
     */
    @PostMapping("/tradeSecondQuotationBidInfo/pollSecQuoBidInfo")
    public Message<List<TradeSecondQuotationBidInfoDto>> pollSecQuoBidInfo(@RequestBody TradeSecondQuotationBidInfoDto tradeSecondQuotationBidInfoDto) {
        List<TradeSecondQuotationBidInfoDto> tradeSecondQuotationBidInfoDtos = tradeSecondQuotationBidInfoService.pollSecQuoBidInfo(tradeSecondQuotationBidInfoDto);
        return MsgUtil.success(tradeSecondQuotationBidInfoDtos);
    }

    /**
     * 根据项目Id查询标段报价列表
     *
     * @author yuezheng
     * @param tradeSecondQuotationBidInfoDto
     * @return org.fzzn.core.model.msg.Message
     * @date 2022/5/17 12:52
     */
    @PostMapping("/tradeSecondQuotationBidInfo/listByProjectId")
    public Message listByProjectId(@RequestBody TradeSecondQuotationBidInfoDto tradeSecondQuotationBidInfoDto) {
        PageResult<TradeSecondQuotationBidInfoDto> pageResult = tradeSecondQuotationBidInfoService.listByProjectId(tradeSecondQuotationBidInfoDto);
        return MsgUtil.msg(pageResult);
    }


    /**
     * Description: 专家提交报价信息
     *
     * @param tradeSecondQuotationBidInfoDto
     * @author: fengbin
     * @date: 2022/2/21 15:56
     * @return: java.lang.Boolean
     */
    @PostMapping("/tradeSecondQuotationBidInfo/saveSecQuoBidInfo")
    public Message<Boolean> saveSecQuoBidInfo(@RequestBody TradeSecondQuotationBidInfoDto tradeSecondQuotationBidInfoDto) {
        if (tradeSecondQuotationBidInfoDto.getEndType().equals("1")) {
            tradeSecondQuotationBidInfoDto.setEndTime(LocalDateTime.now().plusMinutes(tradeSecondQuotationBidInfoDto.getEndStrTime()));
        }
        Boolean aBoolean = tradeSecondQuotationBidInfoService.saveSecQuoBidInfo(tradeSecondQuotationBidInfoDto);
        return MsgUtil.success(aBoolean);
    }
}
